#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

void matmul(ll a[3][3], ll b[3][3], ll c[3][3]) {
  ll res[3][3] = {0};
  rep(i, 0, 2) rep(j, 0, 2) rep(k, 0, 2) {
    res[i][j] = (res[i][j] + a[i][k] * b[k][j] % MOD) % MOD;
  }
  rep(i, 0, 2) rep(j, 0, 2) c[i][j] = res[i][j];
}
void matpow(ll b[3][3], ll p, ll c[3][3]) {
  ll res[3][3] = {0};
  rep(i, 0, 2) res[i][i] = 1;
  while (p) {
    if (p & 1) matmul(res, b, res);
    matmul(b, b, b);
    p >>= 1;
  }
  rep(i, 0, 2) rep(j, 0, 2) c[i][j] = res[i][j];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    if (n <= 3) {
      cout << 1 << endl;
      continue;
    }
    ll b[3][3] = {{0, 1, 0}, {0, 0, 1}, {1, 0, 1}};
    matpow(b, n - 3, b);
    ll ans = (b[2][0] + b[2][1] + b[2][2]) % MOD;
    cout << ans << endl;
  }
  return 0;
}